import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { Table } from 'antd';
import history from '../../../history';
import { connectRouter } from '../../../mixins/router';
// 会员卡片弹窗
import CustomerCart from '../../customerCenter/CustomerCard';

class InsuranceTable extends Component {
  constructor(props) {
    super(props);
    this.state = {
      customerCardVisiblfe: false,
      currentCustomerId: null,
      getPagination: null,
    };
  }

  checkInsurance = (row) => () => {
    history.push(`/videoDoctorDetail/${row.orderId}`);
  };
  tableChange = (pagination) => {
    this.props.pageChange(pagination);
    this.setState({
      getPagination: pagination,
    });
  };
  // 显示会员卡片
  showCustomerCard = (id) => {
    this.setState({
      customerCardVisible: true,
      currentCustomerId: id,
    });
  };
  hideCustomerCard = () => {
    this.setState({
      customerCardVisible: false,
    });
  };

  render() {
    const columns = [
      {
        title: '视频医生订单号',
        dataIndex: 'orderNo',
        key: 'orderNo',
        render: (text, row) => {
          return (
            <Link to={`/videoDoctorDetail/${row.id}`}>
              <span className="clickable">{text}</span>
            </Link>
          );
        },
      },
      {
        title: '服务订单号',
        dataIndex: 'insuranceOrderNo',
        key: 'insuranceOrderNo',
        render: (text, row) => {
          return (
            <Link to={`/patientInsuranceDetail/${row.insuranceOrderId}?r=`}>
              <span className="clickable">{text}</span>
            </Link>
          );
        },
      },
      {
        title: '主/子订单',
        dataIndex: 'orderGrade',
        key: 'orderGrade',
        render: (text, row) => row.orderGrade === 1 ? '主订单' : '子订单',
      },
      {
        title: '卡类型',
        dataIndex: 'cardTypeLabel',
        key: 'cardTypeLabel',
      },
      {
        title: '服务对象',
        dataIndex: 'name',
        key: 'name',
        // crm1012管理列表中增加相应的链接
        render: (text, row) => {
          return (
            <span
              style={{ textDecoration: 'underline', cursor: 'pointer' }}
              onClick={() => this.showCustomerCard(row.insuredId)}
            >
              {text}
            </span>
          );
        },
      },
      {
        title: '视频医生订单状态',
        dataIndex: 'statusLabel',
        key: 'statusLabel',
      },
      {
        title: '创建时间',
        dataIndex: 'createDate',
        key: 'createDate',
      },
    ];
    let data = this.props.tableData;
    return (
      <div className="table-box block">
        <CustomerCart
          id={this.state.currentCustomerId}
          visible={this.state.customerCardVisible}
          hideCustomerCard={this.hideCustomerCard}
        ></CustomerCart>
        <Table
          columns={columns}
          dataSource={data.list}
          rowKey={(record) => record.insurId}
          pagination={{
            showSizeChanger: true,
            total: data.pageIndex !== 1 && data.count === data.pageSize ? data.count + 1 : data.count,
            showTotal: () => `第 ${data.pageIndex} 页`,
            pageSizeOptions: ['10', '20', '50', '100'],
            current: data.pageIndex,
            pageSize: data.pageSize,
          }}
          onChange={this.tableChange}
        />
      </div>
    );
  }
}

export default connectRouter(InsuranceTable);
